/**
 * @author Usuario
 */

flymail.app.ui.MailList = Ext.extend(Ext.grid.GridPanel, {
	gridToolbar: new Ext.Toolbar({
		items: [{
			xtype: 'splitbutton',
			text: 'Reading Pane',
			menu: [{
				text: 'Bottom'
			},{
				text: 'Right',
				handler: function(button){
					maillist.region = 'west';
					maillist.doLayout();
				}
			}]
		}]
	}),
	 
	fromRenderer: function(val, x, store){
		return '<b>' + val + '</b>' + '<br/>' + store.data.subject;
	},
	
	initComponent: function(){
		config = {
			id: 'maillist',
			title: 'Inbox',
			layout: 'fit',
			tbar: this.gridToolbar,
			height: 200,
			minHeight: 200,
			split: true,
			cmargins: '0 0 5 0',
			store: new Ext.data.GroupingStore({
				reader: new Ext.data.ArrayReader({}, [{
					name: 'from'
				}, {
					name: 'date'
				}, {
					name: 'subject'
				}]),
				data: gridData,
				sortInfo: {
					field: 'date',
					direction: "ASC"
				},
				groupField: 'from'
			}),
			columns: [{
				header: "From / Subject",
				width: 40,
				sortable: true,
				dataIndex: 'from',
				renderer: this.fromRenderer
			}, {
				header: "Date",
				width: 30,
				sortable: true,
				dataIndex: 'date'
			}],
			view: new Ext.grid.GroupingView({
				forceFit: true,
				groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
			})
		}
		
		Ext.apply(this, Ext.apply(this.initialConfig, config));
		
		flymail.app.ui.MailList.superclass.initComponent.apply(this, arguments);
	}
});

Ext.reg('fm_maillist', flymail.app.ui.MailList);
